import { defAxios as request } from '@/utils/http'

export function getUsers(data = {}) {
  return request({
    url: '/users',
    method: 'get',
    data
  })
}

export function getUser() {
  return request({
    url: '/index/getUserInfo',
    method: 'get'
  })
}

export function saveUser(data = {}, id) {
  if (id) {
    return request({
      url: '/user',
      method: 'put',
      data
    })
  }

  return request({
    url: `/user/${id}`,
    method: 'put',
    data
  })
}

/**
 * @description: 获取用户列表
 * @param {*} params
 * @return {*}
 */
export function getUserList(params) {
  return request({
    url: '/user/page/list',
    method: 'get',
    params
  })
}
/**
 * @description: 新增用户
 * @param {*} data
 * @return {*}
 */
export function userCreate(data) {
  return request({
    url: '/user/add',
    method: 'post',
    data
  })
}
/**
 * @description: 更新用户
 * @param {*} data
 * @return {*}
 */
export function userUpdate(data) {
  return request({
    url: '/user/edit',
    method: 'put',
    data
  })
}

/**
 * @description: 更新用户状态
 * @param {*} id 用户id
 * @param {*} status 状态
 * @return {*}
 */
export function updateUserStatus({ id, status }) {
  return request({
    url: `/user/edit/status/${id}/${status}`,
    method: 'put'
  })
}

/**
 * @description: 重置密码
 * @param {*} id 用户id
 * @return {*}
 */
export function resetPwd(id) {
  return request({
    url: `/user/resetPwd/${id}`,
    method: 'put'
  })
}
/* 根据部门id 获取用户列表
 * @param {*} params id
 * @returns
 */
export const getDeptPerson = params => request({
  url: `/user/list/dept/${params}`,
  method: 'GET'
})

/**
 * @description: 修改密码
 * @return {*}
 */
export const editPassword = params => request({
  url: `/user/editPwd`,
  method: 'PUT',
  data: params
})
